#pragma once

#include "v2d.h"
#include "drawable.h"

class Rect : public Drawable
{
public:
	V2D<int> min, max;

	Rect(){}
	Rect(int x, int y, int w, int h)
	{
		min = V2D<int>(x,y);
		max = V2D<int>(x+w,y+h);
	}

	void draw(){}
	void draw(int x, int y){}
	void release(){}

	/**
	 * @returns true if the given point parameter is within
	 * the boundaries set up by this rectangle
	 * @param p a (&) reference to a (V2D<int>)point that 
	 * (const) this code is not allowed to modify
	 */
	bool contains(const V2D<int> & p)
	{
		return p.getX() >= min.getX() && p.getX() < max.getX()
			&& p.getY() >= min.getY() && p.getY() < max.getY();
	}

	void addPoint(V2D<int> & p)
	{
		if(min.getX() >= p.getX())
			min.setX(p.getX());
		if(min.getY() >= p.getY())
			min.setY(p.getY());
		if(max.getX() <= p.getX())
			max.setX(p.getX()+1);
		if(max.getY() <= p.getY())
			max.setY(p.getY()+1);
	}

	int width()
	{
		return max.getX() - min.getX();
	}
	int height()
	{
		return max.getY() - min.getY();
	}
	bool isValid()
	{
		return width() > 0 || height() > 0;
	}
};